package com.yangrong.newsservice.service.impl;

import com.yangrong.newsservice.dao.TbArticleLabelDao;
import com.yangrong.newsservice.entity.TbArticleLabelEntity;
import com.yangrong.newsservice.service.TbArticleLabelService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yangrong.common.utils.PageUtils;
import com.yangrong.common.utils.Query;


@Service("tbArticleLabelService")
public class TbArticleLabelServiceImpl extends ServiceImpl<TbArticleLabelDao, TbArticleLabelEntity> implements TbArticleLabelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TbArticleLabelEntity> page = this.page(
                new Query<TbArticleLabelEntity>().getPage(params),
                new QueryWrapper<TbArticleLabelEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<Map<String, Object>> getAllLabelList() {
        List<Map<String, Object>> list = new ArrayList<>();

        List<TbArticleLabelEntity> entityList = baseMapper.selectList(new QueryWrapper<TbArticleLabelEntity>());
        entityList.stream().forEach(item -> {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("label", item.getLabelNameCn());
            map.put("value", item.getId());
            list.add(map);
        });

        return list;
    }

    @Override
    public List<Map<String, Object>> getTagList() {
        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, Object> searchMap = new HashMap<>();
        searchMap.put("is_show_home_tag", 1);
        List<TbArticleLabelEntity> entityList = baseMapper.selectByMap(searchMap);

        Map<String, Object> recommend = new HashMap<>();
        // 加入推荐标签
        recommend.put("name", 0);
        recommend.put("label", "推荐");
        list.add(recommend);

        entityList.stream().forEach(item -> {
            Map<String, Object> map = new HashMap<>();
            map.put("name", item.getId());
            map.put("label", item.getLabelNameCn());
            list.add(map);
        });

        return list;
    }

}